﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using Database;

namespace Business
{
    public class QuanLyDangKi
    {
        TrungTamEntities TrungTam;
        //Constructor
        public QuanLyDangKi()
        {
            TrungTam = new TrungTamEntities();
        }
        public List<String> layDSMaLop()
        {
            var today = DateTime.Today;
            var dsLopHoc = (from lh in TrungTam.LopHocs 
                            where lh.NgayKhaiGiang.Value >= today
                            select lh.MaLop).ToList();
            return dsLopHoc;
        }

        public bool ThemDangKi(HocVien_DangKy hv)
        {
            try{
                TrungTam.AddToHocVien_DangKy(hv);
                TrungTam.SaveChanges();
                return true;
            }catch(Exception ex){
                return false;
            }
        }

        public List<HocVien_DangKy> LayDanhSach()
        {
            var query = (from p in TrungTam.HocVien_DangKy
                         select p).ToList();
            return query;
        }

        public bool XoaDangKi(long STT)
        {
            var hocvien = (from p in TrungTam.HocVien_DangKy
                           where p.STT == STT
                           select p).First();
            try
            {
                TrungTam.DeleteObject(hocvien);
                TrungTam.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }
    }
}
